class Solution:
    def maximumUniqueSubarray(self, nums: list) -> int:
        res = 0
        cur = 0
        visited = set()
        left = 0
        right = 0
        while right < len(nums):
            while nums[right] in visited:
                cur -= nums[left]
                visited.remove(nums[left])
                left += 1
            cur += nums[right]
            visited.add(nums[right])
            res = max(res, cur)
            right += 1

        return res
